# Contributor: Shawn Rose <shawnandrewrose@gmail.com>
# Maintainer: Shawn Rose <shawnandrewrose@gmail.com>
pkgname=zrepl
pkgver=0.6.1
pkgrel=6
pkgdesc="one-stop, integrated solution for ZFS replication"
url="https://zrepl.github.io/"
# s390x: failing tests
arch="all !s390x !armhf"
license="MIT"
makedepends="go bash"
subpackages="
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/zrepl/zrepl/archive/v$pkgver.tar.gz
	go-mod.patch
	zrepl.yml
	zrepl.initd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export GO111MODULE=on
	go build \
		-mod=readonly \
		-ldflags "-X github.com/zrepl/zrepl/version.zreplVersion=v$pkgver" \
		-o "artifacts/zrepl"
	./artifacts/zrepl gencompletion bash ./artifacts/bash-completion
	./artifacts/zrepl gencompletion zsh ./artifacts/zsh-completion
}

check() {
	go test -mod=readonly ./...
}

package() {
	install -Dm0755 artifacts/zrepl "$pkgdir"/usr/bin/zrepl
	install -Dm755 "$srcdir"/zrepl.initd \
		"$pkgdir"/etc/init.d/zrepl
	install -Dm644 "$srcdir"/zrepl.yml \
		"$pkgdir"/etc/zrepl/zrepl.yml
	install -Dm0644 artifacts/bash-completion \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm0644 artifacts/zsh-completion \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
	cd "$builddir/config/samples"
	find ./* -type f -exec install -m 644 -D "{}" "$pkgdir/usr/share/$pkgname/examples/{}" \;
}

sha512sums="
0fb28014f4c50d2512eec2b767883b342f8fc6cd5661dd04bebfb75d9774f4face9402202e2e830c0ca9b831502fdeac1c00e874ea3b0e9188c8df54e353dc70  zrepl-0.6.1.tar.gz
6bc353e47deb993fb89f3ed92db1e328acdfc9a1103b519196b1ede08af5d214fc968f53b6c64e6621ca4aec6c39578a8e2bcfafb168e96c62a7660537c41941  go-mod.patch
ae39a92de1bfd3f0e957b70d02fe05918426fab9203da99d9ee2ee81c173f67e3a55ae525126c4cb0966d0911d7a5bb4c0977915bc0bd11c9a1b607777d39286  zrepl.yml
a6c77686e0189aec4e1ab281d6473c530f9b4371738aca392a6dd6599ed554af9e7d50d68221b4d575bdf3f607640892da34a96d53847d74bbfcf75a25b1836a  zrepl.initd
"
